home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Toolbox / Visual Basic Toolbox (P.I.E.)(1996).ISO / internet / ftp4w22j / sample / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-06-16  |  25.9 KB  |  763 lines

  1. /* **************************************************************
  2.  *
  3.  *
  4.  *      C W _ M A I N 
  5.  * 
  6.  *  This program must be compiled with the model 'Large'
  7.  * **************************************************************** */
  8.  
  9.  
  10.  
  11. #define  STRICT
  12. #include <windows.h>
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15. #include <string.h>
  16. #include <ftp4w.h>
  17. #include "resource.h"
  18.  
  19. #define  INIFILE_NAME   "CW_Main.ini" /* name of ini file */
  20. #define  LOG_FILE       "c:\\ftp4w.log"
  21.  
  22.  
  23. /* user's defined messages */
  24. #define  FTP_LOGGED          (WM_USER + 48)
  25. #define  FTP_DIR             (WM_USER + 51)
  26. #define  FTP_DIRLINEPERLINE  (WM_USER + 52)
  27. #define  FTP_FILETRANSFERED  (WM_USER + 54)
  28. #define  CW_VERBOSE          (WM_USER + 57)
  29. #define  CW_BEGIN            (WM_USER + 60)
  30. #define  CW_QUITAPP          (WM_USER + 63)
  31. #define  SHORT_DIR            FALSE       
  32.  
  33. #define  IsOptOn(x) (GetMenuState (GetMenu(hWnd),x,MF_BYCOMMAND)==MF_CHECKED)
  34.  
  35.  
  36.  
  37. int  nHorzSiz, nVertSiz;
  38. int  nVertPos, nHorzPos;           // scroll pos for debug window
  39. int  nHorzMax, nCurMsg;
  40. int  nMaxMsg;
  41. int  nHorzTab = 20;
  42.  
  43. #define         szAPPLICATION     "CW_MAIN"
  44.  
  45. HINSTANCE       hInst;             /* hInstance of application     */
  46. HWND            hwnd;              /* hWnd of main window          */
  47. BOOL            FirstEmission;
  48. BOOL            bFileTransfer=FALSE; /* TRUE->data transfer in progress */
  49. char            szQuoteCmd[128];     /* Quote Command */
  50. HFILE           hLogFile=HFILE_ERROR; /* Log File */
  51.  
  52.  
  53. /* in main2 : gauge window */
  54. void SetXmitBytes (LONG lBytes, LONG lTotalBytes);
  55. void DeleteXferWindow (void);
  56. void CreateXferWindow(void);
  57. void SetXferWindowText (LPSTR lpStr);
  58. int nCwRegisterClasses(void);
  59. int nCwUnregisterClasses(void);
  60. /* in main2 : scroller window */
  61. int  Ecris(const char *szFormat,...);
  62. void DoPrintf (char * szFormat, ...);
  63. void DoPaint (HWND hwnd);
  64. void DoAddLine (LPSTR szLine);                           
  65. void ReleaseDisplayMem(void);
  66.  
  67. /* in this file */
  68. BOOL InitApplication (HINSTANCE hInstance);
  69. BOOL InitInstance (HINSTANCE hInstance, int nCmdShow);
  70.  
  71.  
  72. /* different system names */
  73. char *szSyst[] = { "Dos", "Windows", 
  74.                    "Unix", "VMS", "CMS", "OS2", NULL };
  75.  
  76. /* ------------------------------ */
  77. /* Get informations from INI file */
  78. /* ------------------------------ */
  79. LPSTR HOST_NAME(void) 
  80. {
  81. static char szBuf[256];
  82.  GetPrivateProfileString ("Connect", "Host", "", szBuf,256, INIFILE_NAME);
  83.   if (szBuf[0]==0)
  84.     {
  85.       MessageBox ( NULL,
  86.                    "Field Host not defined in Cw_Main.Ini", 
  87.                    "CW_MAIN", MB_OK);
  88.       return NULL;
  89.     }
  90.   return szBuf; }  
  91.                         
  92.  
  93. LPSTR USER_NAME(void) 
  94. {
  95. static char szBuf[256];
  96.  GetPrivateProfileString ("Connect", "User", "", szBuf,256, INIFILE_NAME);
  97.   if (szBuf[0]==0)
  98.     {
  99.       MessageBox ( NULL,
  100.                    "Field User not defined in Cw_Main.Ini", 
  101.                    "CW_MAIN", MB_OK);
  102.       return NULL;
  103.     }
  104.   return szBuf; }  
  105.  
  106.  
  107. LPSTR PASSWD_NAME(void) 
  108. {
  109. static char szBuf[256];
  110.  GetPrivateProfileString ("Connect", "PassWd", "", szBuf,256, INIFILE_NAME);
  111.   if (szBuf[0]==0)
  112.     {
  113.       MessageBox ( NULL,
  114.                    "Field PassWd not defined in Cw_Main.Ini", 
  115.                    "CW_MAIN", MB_OK);
  116.       return NULL;
  117.     }
  118.   return szBuf; }  
  119.                         
  120. LPSTR LOCALFILE_NAME(void) 
  121. {
  122. static char szBuf[256];
  123.  GetPrivateProfileString ("Transfer", "LocalFile", "",szBuf,256,INIFILE_NAME);
  124.   if (szBuf[0]==0)
  125.     {
  126.       MessageBox ( NULL,
  127.                    "Field LocalFile not defined in Cw_Main.Ini", 
  128.                    "CW_MAIN", MB_OK);
  129.       return NULL;
  130.     }
  131.   return szBuf; }  
  132.                         
  133.                         
  134. LPSTR REMOTEFILE_NAME(void) 
  135. {
  136. static char szBuf[256];
  137.  GetPrivateProfileString ("Transfer", "RemoteFile", "",szBuf,256,INIFILE_NAME);
  138.   if (szBuf[0]==0)
  139.     {
  140.       MessageBox ( NULL,
  141.                    "Field RemoteFile not defined in Cw_Main.Ini", 
  142.                    "CW_MAIN", MB_OK);
  143.       return NULL;
  144.     }
  145.   return szBuf; }  
  146.  
  147.  
  148. LPSTR NEWREMOTEFILE_NAME(void) 
  149. {
  150. static char szBuf[256];
  151.  GetPrivateProfileString ("Rename", "NewRemoteFile", "",szBuf,256,INIFILE_NAME);
  152.   if (szBuf[0]==0)
  153.     {
  154.       MessageBox ( NULL,
  155.                    "Field NewRemoteFile not defined in Cw_Main.Ini", 
  156.                    "CW_MAIN", MB_OK);
  157.       return NULL;
  158.     }
  159.   return szBuf; }  
  160.  
  161.  
  162. LPSTR REMOTE_DIR(void) 
  163. {
  164. static char szBuf[256];
  165.  GetPrivateProfileString ("Directory", "HostDir", "", szBuf,256, INIFILE_NAME);
  166.   if (szBuf[0]==0)
  167.     {
  168.       MessageBox ( NULL,
  169.                    "Field HostDir not defined in Cw_Main.Ini", 
  170.                    "CW_MAIN", MB_OK);
  171.       return NULL;
  172.     }
  173.   return szBuf; }  
  174.  
  175.  
  176.  
  177. long FileSize (LPSTR szFile)
  178. {
  179. HFILE hF;
  180. long FS;
  181.   hF = _lopen (szFile, 0);
  182.   if (hF==HFILE_ERROR)  return 0;
  183.   FS = _llseek (hF, 0, SEEK_END);
  184.   _lclose (hF);
  185. return FS;
  186. } /* FileSize */
  187.  
  188. //*******************************************************************
  189. LRESULT CALLBACK _export CBQuoteDlg (HWND hWndDlg, UINT message,
  190.                                 WPARAM wParam, LPARAM lParam)
  191. {
  192.    if (message==WM_INITDIALOG)
  193.     {  
  194.       SetDlgItemText (hWndDlg, IDC_QUOTECMD, szQuoteCmd);
  195.       SetFocus (GetDlgItem (hWndDlg, IDC_QUOTECMD));
  196.     }
  197.    if (message==WM_COMMAND)
  198.     {
  199.       switch (wParam)
  200.         {
  201.           case IDOK : GetDlgItemText (hWndDlg, IDC_QUOTECMD, 
  202.                                      szQuoteCmd, sizeof szQuoteCmd);
  203.                       EndDialog (hWndDlg, 0);
  204.                       break;
  205.           case IDCANCEL : EndDialog (hWndDlg, -1);
  206.         }
  207.     }
  208. return FALSE;     
  209. } /* CBQuoteDlgf */                    
  210.  
  211. //*******************************************************************
  212. LRESULT CALLBACK _export MainWndProc (HWND hWnd, UINT message,
  213.                                 WPARAM wParam, LPARAM lParam)
  214. {
  215. static char szBuf[10240];
  216. static char szWinDir[145], szExecCmd [256];
  217. int         Rc;
  218. LPSTR       p, q;
  219. HFILE       hF;
  220. FARPROC     lpfnQuoteDlg;
  221.  
  222.     switch (message)
  223.     {
  224.        case WM_CREATE :
  225.           hwnd = hWnd;
  226.           SetScrollPos (hWnd, SB_HORZ, 0, TRUE);
  227.           SetScrollPos (hWnd, SB_VERT, 0, TRUE);
  228.           SetScrollRange (hWnd, SB_HORZ, 0, 1, TRUE);
  229.           SetScrollRange (hWnd, SB_VERT, 0, 1, TRUE);
  230.           nVertPos = nHorzPos = nHorzMax = nCurMsg = 0;
  231.           nMaxMsg = 80;
  232.           nCwRegisterClasses();
  233.           PostMessage (hWnd, CW_BEGIN, 0, 0);
  234.           break;  
  235.  
  236.  
  237.  
  238.        case WM_VSCROLL:
  239.           switch(wParam)
  240.            {
  241.             case SB_LINEDOWN     : if (nVertPos<(nCurMsg-(nVertSiz>>1))) nVertPos++;  break;
  242.             case SB_LINEUP       : if (nVertPos>0) --nVertPos; break;
  243.             case SB_THUMBPOSITION: nVertPos = min ((WORD) (nCurMsg-(nVertSiz>>1)), LOWORD (lParam)); break;
  244.             case SB_PAGEUP       : nVertPos = (nVertPos>10) ? (nVertPos-10) : 0; break;
  245.             case SB_PAGEDOWN     : nVertPos = (nVertPos<(nCurMsg-nVertSiz)) ? (nVertPos+nVertSiz) : nCurMsg-(nVertSiz>>1); break;
  246.             default              : return 0L;
  247.            } /* switch wParam */
  248.           SetScrollPos (hWnd, SB_VERT, nVertPos, TRUE);
  249.           InvalidateRect (hWnd, NULL, TRUE); 
  250.           return 0L;
  251.  
  252.        case WM_HSCROLL:
  253.           switch (wParam)
  254.            {
  255.             case SB_LINEDOWN     : nHorzPos = (nHorzPos<(nHorzMax-nHorzTab)) ? (nHorzPos+nHorzTab) : nHorzMax; break;
  256.             case SB_LINEUP       : nHorzPos = (nHorzPos>nHorzTab) ? (nHorzPos-nHorzTab) : 0; break;
  257.             case SB_THUMBPOSITION: nHorzPos = min ((WORD) nHorzMax, LOWORD (lParam)); break;
  258.             case SB_PAGEUP       : nHorzPos = (nHorzPos>nHorzSiz) ? (nHorzPos-nHorzSiz) : 0; break;
  259.             case SB_PAGEDOWN     : nHorzPos = (nHorzPos<(nHorzMax-nHorzSiz)) ? (nHorzPos+nHorzSiz) : nHorzMax; break;
  260.             default              : return 0L;
  261.            }
  262.           SetScrollPos (hWnd, SB_HORZ, nHorzPos, TRUE);
  263.           InvalidateRect (hWnd, NULL, TRUE); 
  264.           return 0L;
  265.  
  266.       case WM_PAINT :
  267.           DoPaint (hWnd);
  268.           break;
  269.           
  270.    /* ---------------------------------------------------------- */
  271.  
  272.        case CW_BEGIN :
  273.  
  274.  DoAddLine ("----------------------------------------------------------------");
  275. #ifdef FRANCAIS
  276.           DoAddLine ("Exemple de Programme utilisant FTP4W.DLL");
  277.           DoAddLine ("Les paramΦtres (nom du distant, nom d'utilisateur,...)");
  278.           DoAddLine ("doivent Ωtre entrΘs dans le fichier CW_MAIN.INI ");
  279.           DoAddLine ("comme le montre le fichier donnΘ sur la disquette.");
  280.           DoAddLine (" ");
  281.           DoAddLine ("Ce fichier doit Ωtre copiΘ dans le rΘpertoire de Windows");
  282.           DoAddLine ("Pour l'Θditer, utiliser la commande Options/Edit INI");
  283. #else
  284.           DoAddLine ("Sample program For FTP4W.DLL By Ph. Jounin");
  285.           DoAddLine ("Host description and file names must be defined");
  286.           DoAddLine ("in the file CW_MAIN.INI as shown in the INI file");
  287.           DoAddLine ("provided in the package FTP4W.ZIP.");
  288.           DoAddLine (" ");
  289.           DoAddLine ("Please report bugs and disfonctionments to");
  290.           DoAddLine ("           ark@ifh.sncf.fr");
  291.  #endif /* langues */
  292.  DoAddLine ("----------------------------------------------------------------");
  293.  
  294.           /* add version information */
  295.           Rc = Ftp4wVer (szBuf, sizeof szBuf);
  296.           Ecris ("Version %d.%02X", HIBYTE (Rc), LOBYTE(Rc));
  297.           DoAddLine (szBuf);   
  298.  DoAddLine ("----------------------------------------------------------------");
  299.  
  300.           /* initialize FTP sesson */  
  301.           Rc = FtpInit(hWnd);
  302.           if (Rc!= FTPERR_OK)   
  303.                 Ecris ("FtpInit failed !\nError Code %d", Rc);
  304.           else
  305.              {
  306.                 FtpSetDefaultTimeOut (30);       /* new Timeout : 30 seconds */
  307.                 FtpSetNewDelay(10);
  308.              }
  309.           break;
  310.  
  311.       case WM_CLOSE : 
  312.            DeleteXferWindow ();
  313.            FtpLocalClose ();
  314.            if (FtpRelease!=FTPERR_OK) 
  315.                { 
  316.                  SetTimer (hWnd, 1, 500l, 0);
  317.                  return FALSE; 
  318.                }
  319.            else
  320.              {  
  321.                 ReleaseDisplayMem();
  322.                 DestroyWindow (hWnd);
  323.                 PostQuitMessage (0);
  324.              }
  325.             break;
  326.             
  327.       case WM_TIMER :
  328.            KillTimer (hWnd, 1);
  329.            FtpRelease ();
  330.            ReleaseDisplayMem();
  331.            DestroyWindow (hWnd);
  332.            PostQuitMessage (0);
  333.            break; 
  334.  
  335.       case WM_QUERYENDSESSION :
  336.           FtpLocalClose ();
  337.           FtpRelease ();
  338.           ReleaseDisplayMem();
  339.           DeleteXferWindow ();
  340.           break;
  341.  
  342.       /* --------------------- */
  343.       /* asynchronous Messages */
  344.       /* --------------------- */
  345.       case CW_VERBOSE :
  346.           Ecris ((LPSTR) lParam);
  347.           break;
  348.  
  349.       case FTP_LOGGED :
  350.           Ecris ("Asynchronous Login returns %d", (int) lParam);
  351.           break;
  352.  
  353.           /* Ftp4w sends a message each time an entry has been received */
  354.           /* lParam points on this entry, wParam is FALSE               */
  355.           /* If wParam is TRUE, the directory is finished, one gets the */
  356.           /* the return code of the function.                           */
  357.       case FTP_DIRLINEPERLINE :
  358.           if (! wParam)  DoAddLine ((LPSTR) lParam);
  359.           else  Ecris ("----> FtpDir Returns %d", (int) lParam);
  360.           break;
  361.  
  362.           /* Dir asynchrone : The dir file has been received */  
  363.       case FTP_DIR :
  364.           Ecris ("Dir returns %d", (int) lParam);
  365.           Ecris ("-------");
  366.           hF = _lopen ("$$dir$$.tmp", 0);
  367.           _lread (hF, szBuf, sizeof szBuf);
  368.           _lclose (hF);
  369.           for (p=szBuf ; (q=strchr (p,'\r')) !=NULL ; p=q+2 )
  370.               {  *q=0;
  371.                   DoAddLine (p); }
  372.           Ecris ("-------");
  373.           unlink ("$$dir$$.tmp");
  374.           break;
  375.  
  376.  
  377.        case FTP_FILETRANSFERED :
  378.           if (wParam)
  379.             {
  380.                DeleteXferWindow ();
  381.                Ecris ("Asynchronous transfer returns %d", (int) lParam);
  382.                bFileTransfer = FALSE;
  383.             }
  384.           else
  385.             {
  386.                SetXmitBytes (lParam, FtpBytesToBeTransfered ());
  387.             }  
  388.           break;
  389.                 
  390.  
  391.       /* --------------------- */
  392.       /*     M   E   N   U     */
  393.       /* --------------------- */
  394.       case  WM_COMMAND :
  395.         switch (wParam)
  396.          {
  397.  
  398.            case  CW_ABOUT :
  399.                Ftp4wVer (szBuf, sizeof szBuf);
  400.                Ecris (szBuf);
  401.                break;
  402.                        
  403.            case  CW_CONNECT :
  404.                Ecris ("--- Connection on %s  ---", HOST_NAME () );
  405.                Rc = FtpLogin ( HOST_NAME (), 
  406.                                USER_NAME (), 
  407.                                PASSWD_NAME (),
  408.                                hWnd, FTP_LOGGED);
  409.                Ecris ("Function returns %d", Rc);                              
  410.                break;
  411.  
  412.  
  413.            case CW_RCVAPPEND :
  414.            case CW_RECV :
  415.                Ecris ("Remote %s -> Local %s",REMOTEFILE_NAME (),LOCALFILE_NAME ());
  416.                bFileTransfer = TRUE;
  417.                if (IsOptOn(CW_GAUGE))
  418.                  {
  419.                     CreateXferWindow ();
  420.                     SetXferWindowText (LOCALFILE_NAME());
  421.                  }
  422.                if (wParam==CW_RCVAPPEND)
  423.                     Rc = FtpAppendToLocalFile ( REMOTEFILE_NAME (),
  424.                                   LOCALFILE_NAME (),
  425.                                   IsOptOn(CW_BINARY) ? TYPE_I : TYPE_A, 
  426.                                   IsOptOn(CW_GAUGE),
  427.                                   hWnd, 
  428.                                   FTP_FILETRANSFERED);
  429.                else                                   
  430.                     Rc = FtpRecvFile ( REMOTEFILE_NAME (),
  431.                                   LOCALFILE_NAME (),
  432.                                   IsOptOn(CW_BINARY) ? TYPE_I : TYPE_A, 
  433.                                   IsOptOn(CW_GAUGE),
  434.                                   hWnd, 
  435.                                   FTP_FILETRANSFERED);
  436.                if (! IsOptOn (CW_SYNC) )
  437.                  {       
  438.                     Ecris ("Taille %ld", FtpBytesToBeTransfered () );
  439.                     Ecris ("Async Recv returns %d %s", Rc, 
  440.                             Rc==0 ? "-> Cmd in progress" : "-> Cmd terminated");
  441.                     if (Rc!=0) bFileTransfer=FALSE;
  442.                  }
  443.                else  
  444.                 {
  445.                     DeleteXferWindow ();
  446.                     Ecris ("Recv returns %d", Rc);
  447.                     bFileTransfer = FALSE;
  448.                 }
  449.                break;
  450.  
  451.         
  452.  
  453.  
  454.            case CW_APPEND :
  455.            case CW_SEND :
  456.                Ecris ("Local %s -> Remote %s",LOCALFILE_NAME (),REMOTEFILE_NAME ());
  457.                bFileTransfer = TRUE;
  458.                if (IsOptOn(CW_GAUGE))
  459.                  {
  460.                     CreateXferWindow ();
  461.                     SetXferWindowText (LOCALFILE_NAME());
  462.                  }
  463.                if (wParam==CW_APPEND)
  464.                   Rc = FtpAppendToRemoteFile ( LOCALFILE_NAME (),
  465.                                                REMOTEFILE_NAME (),
  466.                                                IsOptOn(CW_BINARY)?TYPE_I:TYPE_A,
  467.                                                IsOptOn(CW_GAUGE),
  468.                                                hWnd, 
  469.                                               (LPARAM) FTP_FILETRANSFERED);
  470.                else  
  471.                   Rc = FtpSendFile ( LOCALFILE_NAME (),
  472.                                      REMOTEFILE_NAME (),
  473.                                      IsOptOn(CW_BINARY) ? TYPE_I : TYPE_A, 
  474.                                      IsOptOn(CW_GAUGE),
  475.                                      hWnd, 
  476.                                     (LPARAM) FTP_FILETRANSFERED);
  477.                if (! IsOptOn (CW_SYNC) )
  478.                  {       
  479.                     Ecris ("Taille %ld", FtpBytesToBeTransfered () );
  480.                     Ecris ("Async Send returns %d %s", Rc, 
  481.                             Rc==0 ? "-> Cmd in progress" : "-> Cmd terminated");
  482.                     if (Rc!=0)       bFileTransfer = FALSE;
  483.                  }
  484.                else
  485.                  {
  486.                     DeleteXferWindow ();
  487.                     Ecris ("Send returns %d", Rc);
  488.                     bFileTransfer = FALSE;
  489.                  }
  490.                break;
  491.  
  492.  
  493.            case CW_SHORTDIR :
  494.            case CW_LONGDIR :
  495.                Rc=FtpDir (NULL, "$$dir$$.tmp",wParam==CW_LONGDIR,hWnd,FTP_DIR);
  496.                if (Rc!=FTPERR_OK || IsOptOn(CW_SYNC))  
  497.                         PostMessage (hWnd, FTP_DIR, TRUE, Rc);
  498.                break;
  499.  
  500.            case CW_SHORTDIR_LL :
  501.            case CW_LONGDIR_LL :
  502.                if (IsOptOn (CW_SYNC))  
  503.                     DoAddLine ("You MUST be in Asynchronous Mode");
  504.                else     
  505.                  {
  506.                    Rc=FtpDir (NULL, NULL,wParam==CW_LONGDIR_LL,hWnd,FTP_DIRLINEPERLINE);
  507.                    Ecris ("FtpDir returns %d", Rc);
  508.                  }
  509.                break;
  510.  
  511.            case CW_CWD :
  512.               Rc = FtpCWD (REMOTE_DIR ());
  513.               Ecris ("CWD returns %d", Rc);
  514.               break;
  515.  
  516.            case CW_CDUP :
  517.               Rc = FtpCDUP ();
  518.               Ecris ("CDUP returns %d", Rc);
  519.               break;
  520.  
  521.            case CW_PWD :
  522.               Rc = FtpPWD (szBuf, sizeof szBuf);
  523.               if (Rc==FTPERR_OK)  Ecris ("Current dir : %s", szBuf);
  524.               else                Ecris ("FtpPWD returns %d", Rc);
  525.               break;
  526.  
  527.            case CW_RMD :
  528.               Rc = FtpRMD (REMOTE_DIR ());
  529.               Ecris ("ftpRMD returns %d", Rc);
  530.               break;
  531.  
  532.            case CW_MKD :
  533.               Rc = FtpMKD (REMOTE_DIR (), szBuf, sizeof szBuf);
  534.               /* szBuf should be the name of the created dir */
  535.               if (Rc==FTPERR_OK  && szBuf[0]!=0)  
  536.                         Ecris ("Dir %s Has been created", szBuf);
  537.               else      Ecris ("FtpMKD returns %d", Rc);
  538.               break;
  539.  
  540.  
  541.            case CW_DELETE :
  542.               Rc = FtpDeleteFile (REMOTEFILE_NAME ());
  543.               Ecris ("FtpDelete returns %d", Rc);
  544.               break;
  545.             
  546.            case CW_SYST :
  547.               Rc = FtpSyst (szSyst);
  548.               Ecris ("System returns %d -> %s", 
  549.                       Rc, Rc>=1000 ? 
  550.                           Rc==FTPERR_SYSTUNKNOWN ? "Unknown" :"Error" : 
  551.                           szSyst[Rc]);
  552.               break;
  553.  
  554.            case CW_RENAME :
  555.               Rc = FtpRenameFile (REMOTEFILE_NAME (), NEWREMOTEFILE_NAME ());
  556.               Ecris ("Rename returns %d", Rc);
  557.               break;
  558.  
  559.            case CW_FLUSH :
  560.               Rc = FtpFlush ();
  561.               Ecris ("Flush returns %d", Rc);
  562.               break;
  563.  
  564.            case CW_QUOTE :
  565.               lpfnQuoteDlg = MakeProcInstance ((FARPROC) CBQuoteDlg, hInst);
  566.               if (DialogBox(hInst, "QuoteDlg", hWnd, (DLGPROC)lpfnQuoteDlg)==0)
  567.                 {
  568.                     Ecris ("QUOTE %s", szQuoteCmd);
  569.                     Rc=FtpQuote (szQuoteCmd, NULL, 0);
  570.                     Ecris ("Quote returns %d", Rc);
  571.                  }
  572.               FreeProcInstance (lpfnQuoteDlg);
  573.               break;
  574.  
  575.  
  576.            case CW_ABORT :
  577.               Ecris ("Abort");
  578.               FtpAbort ();
  579.               break;  
  580.  
  581.  
  582.            case CW_DISCONNECT : 
  583.                if (bFileTransfer)
  584.                   {
  585.                      Ecris ("File transfer in progress, can not close session");
  586.                   }
  587.                else
  588.                   {
  589.                      Rc = FtpCloseConnection ();
  590.                      Ecris ("FtpCloseConnection returns %d", Rc);
  591.                   }
  592.                break;
  593.  
  594.  
  595.            case CW_QUIT : 
  596.                 PostMessage (hWnd, WM_CLOSE, 0, 0l);
  597.                 break;
  598.                                      
  599.            case CW_SYNC : 
  600.                if (bFileTransfer)
  601.                  {
  602.                    MessageBox (NULL, "Can not change now", "CW_MAIN", MB_OK);
  603.                  }
  604.                else
  605.                  {
  606.                    if (! IsOptOn (CW_SYNC))
  607.                       {
  608.                           CheckMenuItem (GetMenu (hWnd), CW_SYNC, 
  609.                                          MF_BYCOMMAND  | MF_CHECKED);
  610.                           FtpSetSynchronousMode ();
  611.                        }
  612.                    else   
  613.                       {
  614.                           CheckMenuItem (GetMenu (hWnd), CW_SYNC, 
  615.                                          MF_BYCOMMAND  | MF_UNCHECKED);
  616.                           FtpSetAsynchronousMode ();
  617.                        }
  618.                  }
  619.                break;      
  620.                      
  621.            case CW_SETVERB :
  622.                if (IsOptOn (CW_SETVERB))
  623.                    
  624.                  {                
  625.                    CheckMenuItem (GetMenu (hWnd), CW_SETVERB, 
  626.                                   MF_BYCOMMAND  | MF_UNCHECKED);
  627.                    FtpSetVerboseMode (FALSE, hWnd, CW_VERBOSE);
  628.                  }
  629.                else
  630.                  {                
  631.                    CheckMenuItem (GetMenu (hWnd), CW_SETVERB, 
  632.                                   MF_BYCOMMAND  | MF_CHECKED);
  633.                    FtpSetVerboseMode (TRUE, hWnd, CW_VERBOSE);
  634.                  }
  635.                break; 
  636.  
  637.  
  638.            case CW_GAUGE :
  639.                CheckMenuItem (GetMenu (hWnd), CW_GAUGE, MF_BYCOMMAND  | 
  640.                               IsOptOn(CW_GAUGE) ? MF_UNCHECKED : MF_CHECKED); 
  641.                /* pause (for display) each 3 frames if gauge is on */
  642.                if IsOptOn(CW_GAUGE)   FtpSetNewSlices(3, 1);
  643.                else                   FtpSetNewSlices(10, 3);
  644.                break; 
  645.  
  646.  
  647.            case CW_LOG :
  648.                CheckMenuItem (GetMenu (hWnd), CW_LOG, MF_BYCOMMAND  | 
  649.                               IsOptOn(CW_LOG) ? MF_UNCHECKED : MF_CHECKED); 
  650.                if IsOptOn(CW_LOG)   hLogFile =  _lcreat (LOG_FILE, 0);
  651.                else                 
  652.                     {
  653.                       _lclose (hLogFile); 
  654.                       hLogFile = HFILE_ERROR;
  655.                     }
  656.                FtpLogTo (hLogFile);
  657.                break; 
  658.                 
  659.                 
  660.            case CW_BINARY :
  661.                CheckMenuItem (GetMenu (hWnd), CW_BINARY, MF_BYCOMMAND  | 
  662.                               IsOptOn(CW_BINARY) ? MF_UNCHECKED : MF_CHECKED);
  663.                break; 
  664.                 
  665.                 
  666.            case CW_PASSIVE :
  667.                CheckMenuItem (GetMenu (hWnd), CW_PASSIVE, MF_BYCOMMAND  | 
  668.                               IsOptOn(CW_PASSIVE) ? MF_UNCHECKED : MF_CHECKED);
  669.                FtpSetPassiveMode (IsOptOn (CW_PASSIVE));
  670.                break; 
  671.                 
  672.           case CW_EDITINI :
  673.                GetWindowsDirectory (szWinDir, sizeof szWinDir);
  674.                wsprintf (szExecCmd, "NotePad %s\\%s", szWinDir, INIFILE_NAME);
  675.                WinExec (szExecCmd, SW_SHOW);
  676.                break;
  677.                 
  678.             } /* WM_COMMAND */
  679.     }
  680. return DefWindowProc(hWnd, message, wParam, lParam);
  681. } /* Boucle Windows */
  682.  
  683.  
  684.  
  685.  
  686. /* ******************************************************************* */
  687. int PASCAL WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
  688.                         LPSTR lpszCmdLine, int nCmdShow)
  689. {
  690. MSG   msg;
  691.  
  692.     hInst = hInstance;       /* save for use by window procs */
  693.     FirstEmission = (hPrevInstance==NULL);
  694.  
  695.     // Go init this application
  696.     if (    !hPrevInstance  &&  !InitApplication(hInstance) )
  697.         return   FALSE;      /* Exits if unable to initialize */
  698.     if (!InitInstance(hInstance, nCmdShow))   return FALSE;
  699.  
  700.     /* Get and dispatch messages for this applicaton.*/
  701.     while (GetMessage(&msg, NULL, 0, 0))
  702.       {
  703.         TranslateMessage(&msg);
  704.         DispatchMessage(&msg);                  
  705.       }
  706.     UnregisterClass (szAPPLICATION, hInstance);  
  707.     nCwRegisterClasses();
  708.    _lclose (hLogFile); 
  709. return  msg.wParam;
  710. } /* WinMain */
  711.  
  712.  
  713. /* ******************************************************************* */
  714.  
  715. BOOL InitApplication (HINSTANCE hInstance)
  716. {
  717. WNDCLASS wndClass;
  718.  
  719.      wndClass.lpszClassName = szAPPLICATION;
  720.      wndClass.lpszMenuName  = szAPPLICATION;
  721.      wndClass.hInstance     = hInstance;
  722.      wndClass.lpfnWndProc   = MainWndProc;
  723.      wndClass.hCursor       = LoadCursor(hInstance, IDC_ARROW);
  724.      wndClass.hIcon         = LoadIcon  (hInstance, "CW_MAIN");
  725.      wndClass.hbrBackground = (HBRUSH) (1 + COLOR_WINDOW);
  726.      wndClass.style         = CS_VREDRAW | CS_HREDRAW;
  727.      wndClass.cbClsExtra    = 0;
  728.      wndClass.cbWndExtra    = 0;
  729.    // Register the class
  730. return  RegisterClass (&wndClass);
  731. }  /* InitApplication */
  732.       
  733.       
  734.  
  735.  
  736. BOOL InitInstance (HINSTANCE hInstance, int nCmdShow)
  737. {
  738. HWND     hWnd;
  739.  
  740.     hWnd = CreateWindow(
  741.                     szAPPLICATION,     // window class name
  742.                     szAPPLICATION,     // window title
  743.                     WS_OVERLAPPEDWINDOW | WS_HSCROLL | WM_VSCROLL | WS_VISIBLE,
  744.                     CW_USEDEFAULT,          // x - same as dialog box
  745.                     CW_USEDEFAULT,          // y
  746.                     490,                     // cx
  747.                     250,                     // cy
  748.                     NULL,                    // no parent for this window
  749.                     NULL,                    // use the class menu
  750.                     hInstance,               // who created this window
  751.                     NULL                     // no parms to pass on
  752.           );
  753.     if (hWnd==0)  return FALSE;
  754.     ShowWindow (hWnd, nCmdShow);
  755.     UpdateWindow (hWnd);
  756. return TRUE;
  757. }  /* InitInstance */
  758.  
  759.  
  760.  
  761.  
  762.  
  763.